package hah;

public class ReverseInt {
    public int Reverse(int x){
        int ans=0;
        while(x!=0){
            int z=x%10;
            x=x/10;
            //判断是否会溢出  不是很理解
            if (ans > Integer.MAX_VALUE/10 || (ans == Integer.MAX_VALUE / 10 && z > 7)) return 0;
            if (ans < Integer.MIN_VALUE/10 || (ans == Integer.MIN_VALUE / 10 && z < -8)) return 0;

            ans=ans*10+z;

        }
        return ans;
    }
}
